#include "Room.h"

#include "Material.h"

#include <sstream>

Room::Room(const string &_sName)
: m_sName(_sName)
{

}

Room::~Room()
{
	for(unsigned int i = 0; i < m_vMaterialList.size(); i++)
	{
		delete(m_vMaterialList[i]);
	}
}

void Room::addInExit(Exit &_oExit)
{
	this->addInLink(&_oExit);
}

void Room::addOutExit(Exit &_oExit)
{
	this->addOutLink(&_oExit);
}


void Room::addMaterial(Material &_oMaterial)
{
	this->m_vMaterialList += &_oMaterial;
}

void Room::addMaterial(List<Material*> &_vMaterialList)
{
	this->m_vMaterialList.add(_vMaterialList);
}

void Room::clearMaterials()
{
	this->m_vMaterialList.clear();
}

const List<Material*> &Room::getMaterialList() const
{
	return this->m_vMaterialList;
}

const char *Room::getName() const
{
	return this->m_sName.c_str();
}

const Exit *Room::getExit(const unsigned int _uiExitIndex) const
{
	if(_uiExitIndex >= this->getOutLinkList().size())
	{
		return 0;
	}

	return this->getOutLinkList()[_uiExitIndex];
}

const char *Room::reportMaterialList() const
{
	return Material::reportMaterialList(this->m_vMaterialList);
}

const char *Room::reportExitList() const
{
	if(this->getOutLinkList().size() <= 0)
	{
		return "No Exit";
	}

	stringstream ssReport;

	for(unsigned int i = 0; i < this->getOutLinkList().size(); i++)
	{
		ssReport << " " << i+1 << " - " << this->getOutLinkList()[i]->getEndRoom().getName() << endl;
	}

	char * sReport = new char[ssReport.str().size()+1];
	strcpy_s(sReport, ssReport.str().size()+1, ssReport.str().c_str());

	return sReport;
}